if [ ! -n "${1}" ]; then
        echo param 1: module name is null
        exit -1;
fi
if [ ! -n "${2}" ]; then
        echo param2: module version is null
        exit -1;
fi
if [ ! -n "${3}" ]; then
        echo param3: module tomcat is null
        exit -1;
fi
MODULE=${1}
VERSION=${2}
TOMCAT=${3}
LOG=${4}

WAR=/root/wars/$MODULE-$VERSION.war
WEBAPPS=/usr/local/$TOMCAT/webapps

if [ ! -d "$WEBAPPS" ];then
        echo $WEBAPPS is not exits!
        exit -1;
fi

if [ -f "$WAR" ];then
        echo stop service $TOMCAT ...
        service $TOMCAT stop
        echo delete $WEBAPPS/$MODULE ...
        rm -rf $WEBAPPS/$MODULE*
        if [ -n "${4}" ];then
                echo delete all logs in $LOG ...
                rm -rf /var/log/tomcat/$LOG/*
        else
                echo module log is null
        fi
        echo copying $MODULE.war ...
        cp $WAR $WEBAPPS/$MODULE.war
        echo unzip $MODULE.war ...
        unzip -q $WEBAPPS/$MODULE.war -d $WEBAPPS/$MODULE
        echo delete $MODULE.war ...
        rm -rf $WEBAPPS/$MODULE.war
        echo replace development in porduction
        sed -i 's/development/production/g' $WEBAPPS/$MODULE/WEB-INF/web.xml
        echo start service $TOMCAT ...
        service $TOMCAT start
else
        echo $WAR is not exits!
fi